package {{.ModuleName}}impl

import (
	"context"
	"time"

	"gorm.io/gorm"

	"go-caipu/pkg/services/{{.PackageName}}/{{.ModuleName}}"


)

type Service struct {
	store store
}

func ProvideService(db *gorm.DB) (*Service, error) {
	store := ProvideStore(db)
	s := &Service{
		store: store,
	}
	return s, nil
}

func (s *Service) Get{{.ClassName}}Page(ctx context.Context, cmd {{.ModuleName}}.Get{{.ClassName}}PageCommand) (result []{{.ModuleName}}.{{.ClassName}}, num int64, err error) {
	result, num, err = s.store.Get{{.ClassName}}Page(ctx,cmd)
	if err != nil {
		return
	}
	return
}

func (s *Service) Get(ctx context.Context, cmd {{.ModuleName}}.Get{{.ClassName}}Command) ({{.ModuleName}}.{{.ClassName}}, error) {
	return s.store.Get(ctx, cmd)
}

func (s *Service) Insert(ctx context.Context, cmd {{.ModuleName}}.{{.ClassName}}) error {
	return s.store.Insert(ctx, cmd)
}

func (s *Service) Update(ctx context.Context, cmd {{.ModuleName}}.{{.ClassName}}) error {
	cmd.UpdatedAt = time.Now()
	return s.store.Update(ctx, cmd)
}

func (s *Service) Remove(ctx context.Context, cmd {{.ModuleName}}.Remove{{.ClassName}}Command) error {
	return s.store.Remove(ctx, cmd)
}
